<?php
/**
 * CONTENIDO extension pack (mpContenidoX), consists of multiple classes to
 * provide more features for Plugins/Modules.
 *
 * @package     mpContenidoX
 * @subpackage  Globals
 * @author      Murat Purc <murat@purc.de>
 * @copyright   Copyright (c) 2008-2012 Murat Purc (http://www.purc.de)
 * @license     http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2
 * @version     $Id: mpGlobals.class.php 21 2012-07-16 21:33:14Z purcaholic $
 */


defined('CON_FRAMEWORK') or die('Illegal call');

/**
 * @ignore
 */
require_once('mpArrayManager.class.php');


/**
 * Globals array ($GLOBALS) manager class. Provides another way to access (reading/writing) to
 * globals array.
 *
 * Number of access deepness to the array structure depends on extended class 'mpArrayManager'.
 * This is by default up to 4 levels, e. g. $arr['one']['two']['three']['four'].
 *
 * The whole purpose of this class is to replace usage of superglobal $GLOBALS and the global
 * declaration of variables (global $foobar;) within functions.
 * @see http://www.php.net/manual/en/language.variables.scope.php
 *
 *
 * Usage:
 * <code>
 * // example globals content
 * $GLOBALS['key']['subkey']['anotherkey'] = 123;
 *
 * // example access (assuming that access delemiter is /)
 * $glob = mpGlobals::getInstance();
 * echo $glob->get('key/subkey/anotherkey');
 *
 * // example for setting the content
 * $glob->set('key/subkey/anotherkey', 321);
 * </code>
 *
 * @package     mpContenidoX
 * @subpackage  Globals
 * @author      Murat Purc <murat@purc.de>
 */
class mpGlobals extends mpArrayManager implements mpArrayManager_Interface
{
    /**
     * Self instance.
     * @var  mpGlobals
     */
    private static $_instance;

    /**
     * Constructor, stores the reference to $GLOBALS into member variable _aData.
     */
    private function __construct()
    {
        $this->_aData = & $GLOBALS;
    }

    /**
     * Returns a instance of mpGlobals (singleton implementation)
     *
     * @return  mpGlobals
     */
    public static function getInstance()
    {
        if (self::$_instance == null) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

}
